
#include "Int64.h"

#include <math.h>

// DEBUG.
#include "Debug.h"

using namespace Riccsson::System;

REGISTER_CLASS_CPP(Int64)
{

}

//---------------------------------------------------------------------------------------
int Int64::CompareTo(long long* value)
{
	return _internalInt64 > *value ? 1 : _internalInt64 < *value ? -1 : 0;
}
//---------------------------------------------------------------------------------------
int Int64::CompareTo(object* value)
{
	if (!(instanceof(value, Int64)))
		return false;

	return ((Int64*)value)->_internalInt64 == _internalInt64;
}
//---------------------------------------------------------------------------------------
bool Int64::Equals(long long* obj)
{
	return _internalInt64 == *obj;
}
//---------------------------------------------------------------------------------------
bool Int64::Equals(object* obj)
{
	if (!(instanceof(obj, Int64)))
		return false;

	return ((Int64*)obj)->_internalInt64 == _internalInt64;
}
//---------------------------------------------------------------------------------------
int Int64::GetHashCode()
{
	return (int)_internalInt64;
}
//---------------------------------------------------------------------------------------
TypeCode Int64::GetTypeCode()
{
	throw;
}
//---------------------------------------------------------------------------------------
// Static.
int Int64::Parse(string* s)
{
	throw;
}
//---------------------------------------------------------------------------------------
// Static.
int Int64::Parse(string* s, IFormatProvider* provider)
{
	throw;
}
//---------------------------------------------------------------------------------------
// Static.
int Int64::Parse(string* s, Globalization::NumberStyles style)
{
	throw;
}
//---------------------------------------------------------------------------------------
// Static.
int Int64::Parse(string* s, Globalization::NumberStyles style, IFormatProvider* provider)
{
	throw;
}
//---------------------------------------------------------------------------------------
GC_PTR<Riccsson::System::string> Int64::ToString()
{
	bool isNegative(false);
	if(_internalInt64 < 0)
	{
		isNegative = true;
		_internalInt64 = -_internalInt64;
	}

	int length = (int) log10((double) _internalInt64);
	char* intToString = new char[length + 2];

	long long x = _internalInt64;
	long long i = (long long) log10((double) x);
	while(x > 0)
	{
		intToString[i] = (x % 10) + '0';
		x = x / 10;
		i = i - 1;
	}

	intToString[length + 1] = '\0';

	if(isNegative)
	{
		char* intToString2 = new char[length + 2 + 1];
		for(int i = 1; (intToString2[i] = intToString[i-1]) != '\0'; i++);
		intToString2[0] = '-';
		delete intToString;
		intToString = intToString2;
	}

	GC_PTR<string> output( new string(intToString) );

	delete intToString;
	intToString = null;

	return output;
}
//---------------------------------------------------------------------------------------
GC_PTR<Riccsson::System::string> Int64::ToString(IFormatProvider* provider)
{
	throw;
}
//---------------------------------------------------------------------------------------
GC_PTR<Riccsson::System::string> Int64::ToString(string* format)
{
	throw;
}
//---------------------------------------------------------------------------------------
GC_PTR<Riccsson::System::string> Int64::ToString(const char* format)
{
	throw;
}
//---------------------------------------------------------------------------------------
GC_PTR<Riccsson::System::string> Int64::ToString(string* format, IFormatProvider* provider)
{
	throw;
}
//---------------------------------------------------------------------------------------
// Static.
bool Int64::TryParse(string* s, int out result)
{
	throw;
}
//---------------------------------------------------------------------------------------
// Static.
bool Int64::TryParse(string* s, Globalization::NumberStyles style, IFormatProvider* provider, int out result)
{
	throw;
}




//----------------------------------------------------------------------------
// +
Int64 Int64::operator+ ( const Int64 value )
{
	return Int64(this->_internalInt64 + value._internalInt64);
}

//----------------------------------------------------------------------------
// -
Int64 Int64::operator- ( const Int64 value )
{
	return Int64(this->_internalInt64 - value._internalInt64);
}

//----------------------------------------------------------------------------
// *
Int64 Int64::operator* ( const Int64 value )
{
	return Int64(this->_internalInt64 * value._internalInt64);
}

//----------------------------------------------------------------------------
// /
Int64 Int64::operator/ ( const Int64 value )
{
	return Int64(this->_internalInt64 / value._internalInt64);
}
Int64 Int64::operator/ ( const int& value )
{
	return Int64(this->_internalInt64 / value);
}

//----------------------------------------------------------------------------
// %
Int64 Int64::operator% ( const Int64 value )
{
	return Int64(this->_internalInt64 % value._internalInt64);
}

//----------------------------------------------------------------------------
// ++
long long Int64::operator++ ()
{
	return this->_internalInt64++;
}